<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Robocup-denayer-project-a: read-only/trunk/source/muis.cpp Bron Bestand</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Gegenereerd door Doxygen 1.7.1 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Zoeken');
--></script>
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Hoofd&nbsp;Pagina</span></a></li>
      <li><a href="annotated.html"><span>Klassen</span></a></li>
      <li class="current"><a href="files.html"><span>Bestanden</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
          <span class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Zoeken" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </span><span class="right"></span>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&nbsp;Lijst</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>read-only/trunk/source/muis.cpp</h1>  </div>
</div>
<div class="contents">
<a href="muis_8cpp.html">Ga naar de documentatie van dit bestand.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;<a class="code" href="muis_8h.html">muis.h</a>&quot;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a><a class="code" href="muis_8cpp.html#a1d7e79db47d53e873e7b17ffde2b39aa">00014</a> <span class="preprocessor">#define LBZ  -256 //low byte zero (2&#39;s comp)</span>
<a name="l00015"></a><a class="code" href="muis_8cpp.html#a5238d6a995c47331d6c40eaab37bf1db">00015</a> <span class="preprocessor"></span><span class="preprocessor">#define XNEG 0x10</span>
<a name="l00016"></a><a class="code" href="muis_8cpp.html#aaa50f27f1820d8716f21ea3b0a4c1377">00016</a> <span class="preprocessor"></span><span class="preprocessor">#define YNEG 0x20</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span>
<a name="l00018"></a>00018 <span class="keyword">using namespace </span>std;
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="class_muis.html#a1cbba9a9f90ed01fe4657dd1ee137d11">00021</a> <a class="code" href="class_muis.html#a1cbba9a9f90ed01fe4657dd1ee137d11">Muis::Muis</a>(<span class="keywordtype">string</span> dev)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023         cout &lt;&lt; <span class="stringliteral">&quot;Mouse &quot;</span>&lt;&lt; dev &lt;&lt;<span class="stringliteral">&quot; initialize...&quot;</span> &lt;&lt; endl;
<a name="l00024"></a>00024         device=dev;
<a name="l00025"></a>00025         verbose = <span class="keyword">false</span>;
<a name="l00026"></a>00026         devFile.open( dev.c_str() , ios::in | ios::binary);
<a name="l00027"></a>00027         <span class="keywordflow">if</span>( ! devFile.is_open() )
<a name="l00028"></a>00028         {
<a name="l00029"></a>00029                 cout &lt;&lt; <span class="stringliteral">&quot;file not open !!&quot;</span> &lt;&lt; endl;
<a name="l00030"></a>00030         }
<a name="l00031"></a>00031         <a class="code" href="class_muis.html#adb79030b3314ed07c40d88c7597914bf">setDPI</a>(300);
<a name="l00032"></a>00032         <a class="code" href="class_muis.html#a9d8360975a2612654ae625f30433a260">setAngle</a>(0.0);
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="class_muis.html#ae9b83adec443e3393df207639d97a96d">00035</a> <a class="code" href="class_muis.html#ae9b83adec443e3393df207639d97a96d">Muis:: ~Muis</a>(<span class="keywordtype">void</span>)
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037         devFile.close();                 
<a name="l00038"></a>00038         cout &lt;&lt; <span class="stringliteral">&quot;Mouse destructed...&quot;</span> &lt;&lt; endl;  
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="comment">// debug</span>
<a name="l00042"></a><a class="code" href="class_muis.html#a7d8b95e2e7d096c717b99e40cb46a002">00042</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#a7d8b95e2e7d096c717b99e40cb46a002">Muis::reset</a>(<span class="keywordtype">void</span>){
<a name="l00043"></a>00043         x=0;
<a name="l00044"></a>00044         y=0;
<a name="l00045"></a>00045         angle=0;
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a><a class="code" href="class_muis.html#acd343ddb5fc59dc1d57b208c53396d12">00048</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#acd343ddb5fc59dc1d57b208c53396d12">Muis::setVerbose</a>(<span class="keywordtype">bool</span> v)
<a name="l00049"></a>00049 {
<a name="l00050"></a>00050         verbose = v;
<a name="l00051"></a>00051 }
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 <span class="comment">// set correction factors</span>
<a name="l00054"></a><a class="code" href="class_muis.html#a9d8360975a2612654ae625f30433a260">00054</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#a9d8360975a2612654ae625f30433a260">Muis::setAngle</a>(<span class="keywordtype">float</span> a)
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056         angle=a;
<a name="l00057"></a>00057 }
<a name="l00058"></a><a class="code" href="class_muis.html#adb79030b3314ed07c40d88c7597914bf">00058</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#adb79030b3314ed07c40d88c7597914bf">Muis::setDPI</a>(<span class="keywordtype">int</span> d)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060         dpi=d;
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment">// set position</span>
<a name="l00064"></a><a class="code" href="class_muis.html#a313829aa9eb9fe894615756a289adfac">00064</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#a313829aa9eb9fe894615756a289adfac">Muis::setX</a>(<span class="keywordtype">int</span> xi)
<a name="l00065"></a>00065 {
<a name="l00066"></a>00066         x=xi*dpi/25.4;
<a name="l00067"></a>00067 }
<a name="l00068"></a><a class="code" href="class_muis.html#ad2c92a469d7e24869976a040b4cedfe1">00068</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#ad2c92a469d7e24869976a040b4cedfe1">Muis::setY</a>(<span class="keywordtype">int</span> yi)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070         y=yi*dpi/25.4;
<a name="l00071"></a>00071 }
<a name="l00072"></a>00072 
<a name="l00073"></a>00073 <span class="comment">// retrieve position</span>
<a name="l00074"></a><a class="code" href="class_muis.html#a410ea39e18c1170ba371a9ac44ca3ddf">00074</a> <span class="keywordtype">int</span> <a class="code" href="class_muis.html#a410ea39e18c1170ba371a9ac44ca3ddf">Muis::getX</a>(<span class="keywordtype">void</span>)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076         <span class="comment">// return corrected distance</span>
<a name="l00077"></a>00077         <span class="keywordflow">return</span> x*25.4/dpi;
<a name="l00078"></a>00078 }
<a name="l00079"></a><a class="code" href="class_muis.html#a240784255a8ee20a4f9ef85ac4a54fd2">00079</a> <span class="keywordtype">int</span>     <a class="code" href="class_muis.html#a240784255a8ee20a4f9ef85ac4a54fd2">Muis::getY</a>(<span class="keywordtype">void</span>)
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081         <span class="comment">// return corrected distance</span>
<a name="l00082"></a>00082         <span class="keywordflow">return</span> y*25.4/dpi;
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084 
<a name="l00085"></a>00085 <span class="comment">// other</span>
<a name="l00086"></a><a class="code" href="class_muis.html#ac03242a02e234afab031c5ee17c99487">00086</a> <span class="keywordtype">void</span> <a class="code" href="class_muis.html#ac03242a02e234afab031c5ee17c99487" title="Thread::execute();.">Muis::execute</a>()
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088         <span class="keywordtype">char</span> b[3];
<a name="l00089"></a>00089         <span class="keywordtype">int</span> xm,ym,xc,yc;
<a name="l00090"></a>00090         <span class="keywordtype">float</span> a,h,hn;
<a name="l00091"></a>00091         <span class="keywordflow">while</span>(! devFile.eof() &amp;&amp; devFile.is_open())
<a name="l00092"></a>00092         {
<a name="l00093"></a>00093                 devFile.read (b , 3);
<a name="l00094"></a>00094                 <span class="comment">//3 bytes gelezen , zet int op negatief (lower 8 bit 0 laten)</span>
<a name="l00095"></a>00095                 (<a class="code" href="muis_8cpp.html#a5238d6a995c47331d6c40eaab37bf1db">XNEG</a> &amp; b[0])? xm=<a class="code" href="muis_8cpp.html#a1d7e79db47d53e873e7b17ffde2b39aa" title="Muis.">LBZ</a> : xm=0;
<a name="l00096"></a>00096                 (<a class="code" href="muis_8cpp.html#aaa50f27f1820d8716f21ea3b0a4c1377">YNEG</a> &amp; b[0])? ym=<a class="code" href="muis_8cpp.html#a1d7e79db47d53e873e7b17ffde2b39aa" title="Muis.">LBZ</a> : ym=0;
<a name="l00097"></a>00097                 <span class="comment">//de waarde geOR&#39;d op de sign-extended int</span>
<a name="l00098"></a>00098                 ym |= b[2] ;
<a name="l00099"></a>00099                 xm |= b[1] ;
<a name="l00100"></a>00100                 <span class="comment">// correction angle</span>
<a name="l00101"></a>00101                 <span class="keywordflow">if</span>(xm==0)
<a name="l00102"></a>00102                         h=(ym &gt; 0) ? M_PI/2 : -M_PI/2;
<a name="l00103"></a>00103                 <span class="keywordflow">else</span>
<a name="l00104"></a>00104                         h=atan((<span class="keywordtype">float</span>)ym/(<span class="keywordtype">float</span>)xm);
<a name="l00105"></a>00105                 <span class="keywordflow">if</span>(xm &lt; 0) h += M_PI;
<a name="l00106"></a>00106                 a=sqrt(xm*xm+ym*ym);
<a name="l00107"></a>00107                 
<a name="l00108"></a>00108                 cout &lt;&lt; a &lt;&lt; <span class="stringliteral">&quot;,&quot;</span> &lt;&lt; h &lt;&lt; endl;
<a name="l00109"></a>00109                 
<a name="l00110"></a>00110                 hn=h-angle;
<a name="l00111"></a>00111                 xc=a*cos(hn);
<a name="l00112"></a>00112                 yc=a*sin(hn);
<a name="l00113"></a>00113                 <span class="comment">//houd bij hoeveel er bewogen is</span>
<a name="l00114"></a>00114                 x+=(int)xc;
<a name="l00115"></a>00115                 y+=(int)yc;
<a name="l00116"></a>00116                 
<a name="l00117"></a>00117                 <span class="comment">// debug        </span>
<a name="l00118"></a>00118                 <span class="keywordflow">if</span>(verbose)
<a name="l00119"></a>00119                 {
<a name="l00120"></a>00120                         cout &lt;&lt; device &lt;&lt; <span class="stringliteral">&quot; : &quot;</span> &lt;&lt; endl;
<a name="l00121"></a>00121                         cout &lt;&lt; <span class="stringliteral">&quot;data :&quot;</span> &lt;&lt; xm &lt;&lt; <span class="stringliteral">&quot; , &quot;</span> &lt;&lt; ym &lt;&lt; endl;
<a name="l00122"></a>00122                         cout &lt;&lt; <span class="stringliteral">&quot;verpl: x:&quot;</span>&lt;&lt; x &lt;&lt;<span class="stringliteral">&quot;dots, y:&quot;</span>&lt;&lt; y &lt;&lt; <span class="stringliteral">&quot;dots&quot;</span> &lt;&lt; endl;
<a name="l00123"></a>00123                         cout &lt;&lt; <span class="stringliteral">&quot;verpl: x:&quot;</span>&lt;&lt; <a class="code" href="class_muis.html#a410ea39e18c1170ba371a9ac44ca3ddf">getX</a>() &lt;&lt;<span class="stringliteral">&quot;mm, y:&quot;</span>&lt;&lt; <a class="code" href="class_muis.html#a240784255a8ee20a4f9ef85ac4a54fd2">getY</a>() &lt;&lt; <span class="stringliteral">&quot;mm&quot;</span> &lt;&lt; endl;
<a name="l00124"></a>00124                 }
<a name="l00125"></a>00125         }
<a name="l00126"></a>00126         cout &lt;&lt; <span class="stringliteral">&quot;out of execution loop -&gt; not reading data !&quot;</span> &lt;&lt; endl ;
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Gegenereerd op Do 19 Mei 2011 10:15:28 voor Robocup-denayer-project-a door&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
